package com.syaccp.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syaccp.mapper.SysRoleMenuMapper;
import com.syaccp.model.SysRoleMenu;
import com.syaccp.service.SysRoleMenuService;

@Service("sysRoleMenuService")
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

	@Autowired
	private SysRoleMenuMapper sysRoleMenuMapper;

	@Override
	public boolean deleteByRoleId(Integer roleId) {
		LambdaUpdateWrapper<SysRoleMenu> luw = Wrappers.lambdaUpdate();
		luw.eq(SysRoleMenu::getRoleId, roleId);
		return sysRoleMenuMapper.delete(luw) > 0;

	}

	@Override
	public List<Integer> getMenuListByRoleId(Integer roleId) {

		LambdaQueryWrapper<SysRoleMenu> lqw = Wrappers.lambdaQuery();
		lqw.select(SysRoleMenu::getMenuId);
		lqw.eq(SysRoleMenu::getRoleId, roleId);
		List<SysRoleMenu> roleMenuList = sysRoleMenuMapper.selectList(lqw);
		return roleMenuList.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
	}

}
